package edu.pku.sei.modeler.handler;

import org.eclipse.draw2d.Locator;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.handles.AbstractHandle;
import org.eclipse.gef.palette.CreationToolEntry;
import org.eclipse.gef.palette.PaletteDrawer;
import org.eclipse.gef.palette.PaletteEntry;

/**
 * Factory used to create appropriate ActionHandle.
 * 
 * @author dumoulin
 */
public class ActionHandleFactory {

	/**
	 * Create an ActionHandle for the specified toolEntry.
	 * 
	 * @param locator
	 * @param owner
	 * @param paletteEntry
	 * 
	 * @return
	 */
	public AbstractHandle createActionHandleFor(GraphicalEditPart owner,
			PaletteEntry paletteEntry, Locator locator) {
		if (paletteEntry instanceof PaletteDrawer) {
			return new ActionHandleContainer(owner,
					(PaletteDrawer) paletteEntry, locator, this);
		} else if (paletteEntry instanceof CreationToolEntry) {
			return new CreationToolEntryActionHandle(owner,
					(CreationToolEntry) paletteEntry, locator);
		}
		return null;

	}
}